package logic

import (
	"box-mart-api/boxrpc/boxrpc"
	"box-mart-api/boxrpc/internal/svc"
	"box-mart-api/models/mysql"
	"context"
	"errors"

	"github.com/zeromicro/go-zero/core/logx"
)

type BoxDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBoxDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BoxDetailLogic {
	return &BoxDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *BoxDetailLogic) BoxDetail(in *boxrpc.BoxDetailRequest) (*boxrpc.BoxDetailResponse, error) {
	// todo: add your logic here and delete this line
	var box mysql.Box
	err := box.BoxDetail(mysql.DB, in.BoxId)
	if err != nil {
		return nil, errors.New("查询失败")
	}

	return &boxrpc.BoxDetailResponse{
		BoxId:    int64(box.ID),
		BoxTitle: box.BoxTitle,
		BoxName:  box.BoxName,
		BoxPrice: box.BoxPrice,
		BoxType:  box.BoxType,
	}, nil

}
